<?php

/**
 * Controlador del LOGIN
 * 
 * @category   Controller
 * @package    modules_LOGIN_models
 * @author     Jose Miguel De Jesus <josejm07@hotmail.com>
 * @copyright  Todos los derechos reservados. curriculumvitae.net. 2013.
 * 
 * @see        Administrador
 * @since      Version 1.0, revision 1.
 */
class login_user extends CI_Controller {
    
    /** 
     * Inicialisa el constructor de CI_Controller
     */
    public function __construct()
	{
		parent::__construct();
                
                $this->load->model(array('general/home/model/gn_usuarios_model'));
        	}
	
        /**
	 * 
	 * Esta funcion index es la que me va a cargar la vista.
	 */
	public function index()
	{
            $newdata = array(
            'username' => '',
            'logged_in' => False);
                                   
        $this->session->set_userdata($newdata);
        
        $session = $this->session->all_userdata();
        
          if($session['logged_in']){
               
               
               
           }  else {
               
               $this->load->view('aplicacion/vista/login/login_user');
               
           }
         
        }
        
        /**
	 * 
	 * Valida la entrada del formulario de ligin
	 */
        public function validar()
        {
           
            $this->form_validation->set_rules('username', 'username', 'required|min_length[5]|max_length[30]|xss_clean');

        $this->form_validation->set_rules('password', 'Password', 'trim|required|md5');

        if ($this->form_validation->run() == FALSE) {
            $this->index();
        } else {

            $username = $this->input->post('username');
            $password = $this->input->post('password');

            if ($this->gn_usuarios_model->validarUsuario($username, $password)) {

                $newdata = array(
                    'username' => $username,
                    'logged_in' => TRUE);

                $this->session->set_userdata($newdata);
                
                redirect('/mantenimientos/nombreCompleto');
            } else {

                $this->index();
            }
        }
    }

}

?>
